﻿//********************************************************************************//
//创建日期：<创建日期，2016-09-06>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：预置信息
//********************************************************************************//
using BLL;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;


namespace Web.Pages.QuShui.DiXiaS.JiChuXX
{
    public partial class YuZhiXX : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource1
        {
            get
            {
                return ViewState["dtSource1"] as DataTable;
            }
            set
            {
                ViewState["dtSource1"] = value;
            }
        }

        private DataTable dtSource2
        {
            get
            {
                return ViewState["dtSource2"] as DataTable;
            }
            set
            {
                ViewState["dtSource2"] = value;
            }
        }

        #endregion

        #region 变量
        /// <summary>
        /// 井标记信息
        /// </summary>
        QS_JX_JINGBIAOJXX _QS_JX_JINGBIAOJXX = new QS_JX_JINGBIAOJXX();

        /// <summary>
        /// 井标记信息bll
        /// </summary>
        QS_JX_JINGBIAOJXXBLL _QS_JX_JINGBIAOJXXBLL = new QS_JX_JINGBIAOJXXBLL();

        /// <summary>
        /// 表标记信息
        /// </summary>
        QS_JX_BIAOBIAOJXX _QS_JX_BIAOBIAOJXX = new QS_JX_BIAOBIAOJXX();

        /// <summary>
        /// 表标记信息bll
        /// </summary>
        QS_JX_BIAOBIAOJXXBLL _QS_JX_BIAOBIAOJXXBLL = new QS_JX_BIAOBIAOJXXBLL();
        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
                LoadData1();
                LoadData2();
            }
            //每次回发时从内存中取得数据源重新绑定,否则列头无法排序
            this.gvList.DataSource = this.dtSource1;
            this.gvList.DataBind();
            this.gvList2.DataSource = this.dtSource2;
            this.gvList2.DataBind();
        }

       
        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "info")
            {
                DataTable dtxx = _QS_JX_JINGBIAOJXXBLL.SelectQS_JX_JINGBIAOJXXesDynamic(string.Format("i_jlzt=0 and id={0}", id), null);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(dtxx.Rows[0]["S_YUZHIBH"], dtxx.Rows[0]["S_YUZHIMC"], dtxx.Rows[0]["S_BEIZHU"]);
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "del")
            {
                this._QS_JX_JINGBIAOJXX = _QS_JX_JINGBIAOJXXBLL.SelectQS_JX_JINGBIAOJXX(id);
                //设置逻辑删除
                this._QS_JX_JINGBIAOJXX.I_JLZT = -1;
                //执行操作
                _SYS_LOGBLL.Log<QS_JX_JINGBIAOJXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "井标记信息", OperateState.Delete, _QS_JX_JINGBIAOJXX, null);
                if (_QS_JX_JINGBIAOJXXBLL.InsertOrUpdate(_QS_JX_JINGBIAOJXX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "操作成功！";
                    e.Result = cr.ToString();
                    return;
                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;

                //添加
                if (id == -1)
                {
                    this._QS_JX_JINGBIAOJXX.ID = 0;
                    this._QS_JX_JINGBIAOJXX.I_JLZT = 0;
                    operateState = OperateState.Add;
                    //判断井标记编号是否存在
                    if (_QS_JX_JINGBIAOJXXBLL.SelectQS_JX_JINGBIAOJXXesDynamic(string.Format("I_JLZT=0 and S_YUZHIBH='{0}'", this.txtBiaoHao.Text), null).Rows.Count > 0)
                    {
                        cr.IsSuccess = false;
                        cr.IsAlertMsg = true;
                        cr.Msg = "您所输入井标记编号系统中已经存在使用,请重新输入。";
                        e.Result = cr.ToString();
                        return;
                    }
                }
                //修改
                else
                {
                    //修改操作
                    this._QS_JX_JINGBIAOJXX = _QS_JX_JINGBIAOJXXBLL.SelectQS_JX_JINGBIAOJXX(id);
                    operateState = OperateState.Modify;
                }

                

                _QS_JX_JINGBIAOJXX.S_YUZHIBH = txtBiaoHao.Text;
                _QS_JX_JINGBIAOJXX.S_YUZHIMC = txtMingCheng.Text;
                _QS_JX_JINGBIAOJXX.S_BEIZHU = txtMiaoShu.Text;
                //设置操作信息
                _QS_JX_JINGBIAOJXX.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                _QS_JX_JINGBIAOJXX.D_CAOZUORQ = DateTime.Now;
                _SYS_LOGBLL.Log<QS_JX_JINGBIAOJXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "井标记信息", operateState, _QS_JX_JINGBIAOJXX, null);
                if (_QS_JX_JINGBIAOJXXBLL.InsertOrUpdate(_QS_JX_JINGBIAOJXX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "保存成功！";
                    cr.SpecialIndetity = _QS_JX_JINGBIAOJXX.ID.ToString();
                    e.Result = cr.ToString();
                    return;
                }
            }
           else if (e.Parameter == "info2")
            {
                DataTable dtxx = _QS_JX_BIAOBIAOJXXBLL.SelectQS_JX_BIAOBIAOJXXesDynamic(string.Format("i_jlzt=0 and id={0}", id), null);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(dtxx.Rows[0]["S_BIAOBH"], dtxx.Rows[0]["S_BIAOMINGC"], dtxx.Rows[0]["S_MIAOSHU"]);
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "del2")
            {
                this._QS_JX_BIAOBIAOJXX = _QS_JX_BIAOBIAOJXXBLL.SelectQS_JX_BIAOBIAOJXX(id);
                //设置逻辑删除
                this._QS_JX_BIAOBIAOJXX.I_JLZT = -1;
                //执行操作
                _SYS_LOGBLL.Log<QS_JX_BIAOBIAOJXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "表标记信息", OperateState.Delete, _QS_JX_BIAOBIAOJXX, null);
                if (_QS_JX_BIAOBIAOJXXBLL.InsertOrUpdate(_QS_JX_BIAOBIAOJXX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "操作成功！";
                    e.Result = cr.ToString();
                    return;
                }
            }
            else if (e.Parameter == "save2")
            {
                OperateState operateState;

                //添加
                if (id == -1)
                {
                    this._QS_JX_BIAOBIAOJXX.ID = 0;
                    this._QS_JX_BIAOBIAOJXX.I_JLZT = 0;
                    operateState = OperateState.Add;
                    //判断井标记编号是否存在
                    if (_QS_JX_BIAOBIAOJXXBLL.SelectQS_JX_BIAOBIAOJXXesDynamic(string.Format("I_JLZT=0 and S_BIAOBH='{0}'", this.txtBiaoHao2.Text), null).Rows.Count > 0)
                    {
                        cr.IsSuccess = false;
                        cr.IsAlertMsg = true;
                        cr.Msg = "您所输入表标记编号系统中已经存在使用,请重新输入。";
                        e.Result = cr.ToString();
                        return;
                    }
                }
                //修改
                else
                {
                    //修改操作
                    this._QS_JX_BIAOBIAOJXX = _QS_JX_BIAOBIAOJXXBLL.SelectQS_JX_BIAOBIAOJXX(id);
                    operateState = OperateState.Modify;
                }
                

                _QS_JX_BIAOBIAOJXX.S_BIAOBH = txtBiaoHao2.Text;
                _QS_JX_BIAOBIAOJXX.S_BIAOMINGC = txtMingCheng2.Text;
                _QS_JX_BIAOBIAOJXX.S_MIAOSHU = txtMiaoShu2.Text;
                //设置操作信息
                _QS_JX_BIAOBIAOJXX.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                _QS_JX_BIAOBIAOJXX.D_CAOZUORQ = DateTime.Now;
                _SYS_LOGBLL.Log<QS_JX_BIAOBIAOJXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "表标记信息", operateState, _QS_JX_BIAOBIAOJXX, null);
                if (_QS_JX_BIAOBIAOJXXBLL.InsertOrUpdate(_QS_JX_BIAOBIAOJXX, null))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "保存成功！";
                    cr.SpecialIndetity = _QS_JX_BIAOBIAOJXX.ID.ToString();
                    e.Result = cr.ToString();
                    return;
                }
            }

        }

        /// <summary>
        /// 列表刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList2_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            LoadData2();
        }

        /// <summary>
        /// 列表刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            LoadData1();
        }
        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {

        }

        /// <summary>
        /// 数据加载1
        /// </summary>
        private void LoadData1()
        {
            this.dtSource1 = _QS_JX_JINGBIAOJXXBLL.SelectQS_JX_JINGBIAOJXXesDynamic("i_jlzt=0", "S_YUZHIBH");
            this.gvList.DataSource = this.dtSource1;
            this.gvList.DataBind();
        }

        /// <summary>
        /// 数据加载1
        /// </summary>
        private void LoadData2()
        {
            this.dtSource2 = _QS_JX_BIAOBIAOJXXBLL.SelectQS_JX_BIAOBIAOJXXesDynamic("i_jlzt=0", "S_BIAOBH");
            this.gvList2.DataSource = this.dtSource2;
            this.gvList2.DataBind();
        }

        #endregion        

    }
}